
const dao = require("../dao/star")
const response = require("../utils/response")
const { checkauth } = require("../utils/check");

/**
 * 收藏
 * @param {*} data {secret_id, user_id, post_id}
 */
async function add_star(data) {
    let auth = await checkauth(data.secret_id, data.user_id);
    if (!auth) {
        return response.forbidden("权限错误");
    }
    await dao.add_star(data.user_id, data.post_id);
}

/**
 * 取消收藏
 * @param {*} data {secret_id, user_id, post_id}
 */
async function del_star(data) {
    let auth = await checkauth(data.secret_id, data.user_id);
    if (!auth) {
        return response.forbidden("权限错误");
    }
    await dao.del_star(data.user_id, data.post_id);
}

module.exports = {
    add_star: add_star,
    del_star: del_star,
}
